var json = {"media":["twitter", "news"]};
var news_interval = 4000; //milliseconds
var news_timer;
var news_items_count = 3;
var count = 0;

function hide_media (id) {
	var media = document.getElementById(id + "_contents");
	if (media != null) {
		media.style.display="none";
		var tab =  document.getElementById(id);
		tab.className =  id + "_tab_unselected";
	}
}

function show_media(id) {
	for (_m in json.media) {
		hide_media (json.media[_m]);
	}
	var media = document.getElementById(id + "_contents");
	media.style.display="block";
	var tab =  document.getElementById(id);
	tab.className =  id + "_tab_selected";
}

function save_breaking_news() {
	var breaking_news = document.getElementById("new_news_item");
	var text = breaking_news.innerHTML;
	text = text.replace("&nbsp;", "");
	var code =base64_encode(text);
	var result = getFile("/modules/social_media/save_breaking_news.php?news=" + code)
   if (result == "saved") {
	   var added_news = document.getElementById("added_news");
	   added_news.innerHTML = text;
	   breaking_news.innerHTML = "&nbsp;";
   }
	
}

function loop_news_feed () {
	var news_items = document.getElementById("news_items");
	count++;
	
	$.ajax({
            async: false,
            type: 'GET',
            url: "http://" + top.location.host + "/modules/articles/content/about/news_events/news.html",
        
            success: function (result) {
                news_items.innerHTML = "<b>Lastest News</b><br>" + result;
            }
        });
        
 	$.ajax({
            async: false,
            type: 'GET',
            url: "http://" + top.location.host + "/modules/articles/content/about/news_events/events.html",
        
            success: function (result) {
                news_items.innerHTML = news_items.innerHTML + "<hr><b>Lastest Events</b><br>"  + result;
            }
        });       
        
        
	news_timer = setTimeout ( "loop_news_feed ()", news_interval );
	
}
